--列阵
local liezhen = fk.CreateSkill {
    name = "mcdh_liezhen",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

liezhen:addEffect('active',{
    can_use = function (self, player)
        return table.every(Fk:currentRoom().alive_players, function(p)
            return #table.filter(p:getEquipments(Card.SubtypeArmor), function(cid)
                return Fk:getCardById(cid).name == "mcdh_metalcrab"
            end) == 0
        end)
    end,
    card_filter = Util.FalseFunc,
    card_num = 0,
    target_num = 1,
    target_filter = function(self,player, to_select, selected, selected_cards)
        local target = to_select
        return #selected == 0 and target and target.dead == false and
                #target:getAvailableEquipSlots(Card.SubtypeArmor) > 0
    end,
    on_use = function (self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local card = table.find(U.prepareDeriveCards(room, {{"mcdh_metalcrab", Card.Club, 7}}, "mcdh_metalcrab_cardid"), function (id)
            return player.room:getCardArea(id) == Card.Void
        end)
        if card then
            room:setCardMark(Fk:getCardById(card), MarkEnum.DestructOutMyEquip, 1)
            if  not target.dead and not target:isProhibited(target,  Fk:getCardById(card)) then
                room:useCard({
                    from = target,
                    tos = {target},
                    card =  Fk:getCardById(card)
                ,
                })
            end
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_liezhen"] = "列阵",
    [":mcdh_liezhen"] = "出牌阶段，若场上没有【磐蟹】，你可以令一名角色从游戏外使用一张【磐蟹】。<br/>" ..
            "<font color='grey'><small>【磐蟹】<br>♣7 装备牌·防具<br/><b>防具技能</b>：<br/>" ..
            "1.锁定技，当你使用或打出手牌后，若此牌与【磐蟹】下的牌类别均不同，你将一张手牌置于【磐蟹】下。<br/>" ..
            "2.锁定技，当你受到伤害后，或【磐蟹】离开你的装备区时，你销毁此牌并摸一张牌<br/>" ..
            "</small></font>",
}

return liezhen